import axios from 'axios'
import qs from 'qs'
//此路径为配置代理服务器时的代理路径

export function qsData(data) {
	return qs.stringify(data);
}
 

export default {
	post(url, data, success_res, fail_res) {
		return axios.post("/api"+url, qsData(data))
			.then(res => {
				if (res.data.code != 200) {
					if (fail_res) {
						console.log('请求失败!');
						fail_res(res)
					}
				} else {
					if (success_res) {
						console.log('请求成功!');
						success_res(res)
					}
				}
			})
			.catch((error) => {
				
			})

	},
	get(url, data) {
		return axios.get(url, qsData(data))
			.then(res => {
				if (res.data.code != 200) {
					if (fail_res) {
						console.log('请求失败!');
						fail_res(res)
					}
				} else {
					if (success_res) {
						console.log('请求成功!');
						success_res(res)
					}
				}
			})
			.catch((error) => {
				console.log('请求出错!');
			})
	}
}
